/**
 * 
 * 工作流操作的 JS 工具
 * 
 */


Work = function(){
	
	
	
	
	//保存数据
	this.saveData = function(callback){
		CQOA.formSubmit($('#dataProcessForm'),ctx+'/work/saveData.action',function(o){
			if(o.success){
				$("#dataProcessForm").form("load",  o.result);
				if(typeof callback != "undefined" && $.isFunction(callback)){
					callback();
           	 	}
			}
			$.messager.show({
				msg : o.msg
			});
		},{});
	};
	
	this.nextProcess = function(){
		this.saveData(function(){
			CQOA.load('taskPopup',ctx + '/wfc/Task!taskOper.action',{'entity.sid':$('#taskId').val()},function(){
				showHideFun('taskPopup','open');
			});
		});
	};
	
};

/**任务完成*/
CQOA.completeTaskCallback = function(rows,opTypes,activityId){
	var nextTaskInstances = "";
	if(rows.length==0){
		nextTaskInstances ="@@@";
	}
	 //字段验证
     for (var i = 0; i < rows.length; i++) {
            	var id = rows[i].id;
            	var prefix = id.substring(0, 1);
            	if(prefix == "u"){
            		id = id.substring(1, id.length);
            	}
                nextTaskInstances = nextTaskInstances + activityId;
                nextTaskInstances = nextTaskInstances + "@" + id;
				nextTaskInstances = nextTaskInstances + "@" + rows[i].text;//名称
                nextTaskInstances = nextTaskInstances + ",";
    }
   //封装URL参数
     var params = {
         "dto.taskId": $("#taskId").val(),
         "dto.nextTaskOpers": nextTaskInstances,
         "dto.type": $("#businessType").val(),
         "dto.businessId": $("#businessId").val(),
		 "dto.activityId" : activityId
     };
     try {
         $.post(ctx+'/work/completeTask.action', params, function(data){
             if (data.success) {
                 $.messager.show({
                     msg: "操作成功"
                 });
                 Task_Return();//返回
             }else {
                 $.messager.show({
                     msg: data.msg
                 });
             }
         });
     } 
     catch (e) {
         $.messager.show({
             msg: e.message
         });
     }
};


function Task_Return(){
	if(typeof comeback != "undefined" && $.isFunction(comeback)){
		comeback();
	}
	if($('#taskGrid')){
		$('#taskGrid').datagrid('reload');
	}
	
};


var work = new Work();